package com.weixing.mall.provider.controller.cms;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.model.dto.cms.HelpDocDto;
import com.weixing.mall.provider.model.query.HelpDocQuery;
import com.weixing.mall.provider.service.IHelpDocService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName HelpDocController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/7/26
 * @Version 1.0
 **/
@RestController
@RequestMapping("helpDoc")
@Api(value = "帮助管理APi", tags = "帮助管理")
public class HelpDocController extends BaseController {

    @Autowired
    private IHelpDocService helpDocService;


    @ApiOperation(value = "加载帮助管理列表")
    @GetMapping("")
    public Result list(HelpDocQuery helpDocQuery){
        return ResultUtil.success(helpDocService.selectOfPage(initMpPage(),helpDocQuery));
    }

    @ApiOperation(value = "保存帮助管理信息")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated HelpDocDto helpDocDto,@SysInfo SysAuth auth){
        helpDocService.save(helpDocDto,auth.getUid());
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除帮助管理信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "帮助管理id", paramType = "path", dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return helpDocService.removeById(id)? ResultUtil.success() : ResultUtil.error();
    }

    @ApiOperation(value = "查询帮助管理信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "帮助管理id", paramType = "path", dataType = "long")
    })
    @GetMapping("/{id}")
    public Result get(@PathVariable Long id){
        return ResultUtil.success(helpDocService.selectHelpDocVoById(id));
    }

}
